package delete;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

//客户端
public class TCP11 {
    public static void main(String[] args) throws Exception {

        Socket socket=new Socket(InetAddress.getByName("localhost"),9999);

        OutputStream outputStream = socket.getOutputStream();

        FileInputStream in=new FileInputStream("GY.jpg");


        byte[] buffer=new byte[1024];
        int len;
        while ((len=in.read(buffer))!=-1){
            outputStream.write(buffer,0,len);
        }

        socket.shutdownOutput();//通知服务器我已经传输完毕

        InputStream inputStream = socket.getInputStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();//接收字符、就用字节的管道流
        byte[] buff2 = new byte[1024];
        int len2;
        while ((len2 = inputStream.read(buff2)) != -1) {
            bos.write(buff2, 0, len2);
        }
        System.out.println(bos.toString());


        //5.释放资源
        bos.close();
        inputStream.close();
        in.close();
        outputStream.close();
        socket.close();




    }
}
